package cn.stylefeng.guns.modular.kh.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.kh.entity.KhTzStorageOrderItem;
import cn.stylefeng.guns.modular.kh.mapper.KhTzStorageOrderItemMapper;
import cn.stylefeng.guns.modular.kh.model.params.KhTzStorageOrderItemParam;
import cn.stylefeng.guns.modular.kh.model.result.KhTzStorageOrderItemResult;
import  cn.stylefeng.guns.modular.kh.service.KhTzStorageOrderItemService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 提总分拣任务 服务实现类
 * </p>
 *
 * @author zzh
 * @since 2025-10-23
 */
@Service
public class KhTzStorageOrderItemServiceImpl extends ServiceImpl<KhTzStorageOrderItemMapper, KhTzStorageOrderItem> implements KhTzStorageOrderItemService {

    @Override
    public void add(KhTzStorageOrderItemParam param){
        KhTzStorageOrderItem entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(KhTzStorageOrderItemParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(KhTzStorageOrderItemParam param){
        KhTzStorageOrderItem oldEntity = getOldEntity(param);
        KhTzStorageOrderItem newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public KhTzStorageOrderItemResult findBySpec(KhTzStorageOrderItemParam param){
        return null;
    }

    @Override
    public List<KhTzStorageOrderItemResult> findListBySpec(KhTzStorageOrderItemParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(KhTzStorageOrderItemParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(KhTzStorageOrderItemParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private KhTzStorageOrderItem getOldEntity(KhTzStorageOrderItemParam param) {
        return this.getById(getKey(param));
    }

    private KhTzStorageOrderItem getEntity(KhTzStorageOrderItemParam param) {
        KhTzStorageOrderItem entity = new KhTzStorageOrderItem();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
